<style>
    .form-group label{width:100px}
    .task .form-group{width: 90%;}
</style>
<section class="content task" >
    <div class="row">
        <div class="col-md-12">
            <div class="box box-danger">
                <div class="box-body">
                    <form id="site_public_editinfo_form">
                        <input type="hidden" name="id" value="{$data.id}" />
                        <div class="form-group"  >
                            <label style="display:inline-table">线路
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <select class="form-control " data-placeholder="请输入线路编号或起始站点" style="width: 60%"
                                    name="roads_id">
                                <option value="{$data['roads_id']}" selected></option>
                            </select>
                            <input type="hidden" id="sitelonglat" />
                        </div>
                        <div class="form-group">
                            <label style="display:inline-table">方量
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <input type="text" value="{$data['total_load']}" name="total_load" />(需小于车辆载重)
                            <!--<foreach name="car_load" item="vo">-->
                                <!--<input type="radio" value="{$vo}" name="total_load"  <eq name="data['total_load']" value="$vo"> checked="checked"</eq>>&nbsp;&nbsp;{$vo}方&nbsp;&nbsp;-->
                            <!--</foreach>-->
                        </div>
                        <div class="form-group">
                            <label style="display:inline-table">卸料方式
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <input type="radio" value="0" name="unload_type"  <eq name="data['unload_type']" value="0"> checked="checked"</eq> <eq name="data['taidiao']" value=""> checked="checked"</eq>>&nbsp;&nbsp;泵送&nbsp;&nbsp;
                            <input type="radio" value="1" name="unload_type"  <eq name="data['unload_type']" value="1"> checked="checked"</eq>>&nbsp;&nbsp;塔吊&nbsp;&nbsp;
                            <input type="radio" value="2" name="unload_type"  <eq name="data['unload_type']" value="2"> checked="checked"</eq>>&nbsp;&nbsp;直卸&nbsp;&nbsp;
                            <input type="radio" value="3" name="unload_type"  <eq name="data['unload_type']" value="3"> checked="checked"</eq>>&nbsp;&nbsp;斗卸&nbsp;&nbsp;
                        </div>
                        <div class="form-group">
                            <label style="display:inline-table">运输车辆
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <input type="text" placeholder="选择车辆"
                                   class="form-control"
                                    id="def_carname"  <if condition='isset($data["car_name"])'>value="{$data.car_name} 车号:{$data.car_no}"</if>
                                   style="display:inline;width: 70%" readonly onclick="getCar()">
                            <input type="hidden"
                                   name="car_id" id="car_id" value="{$data.car_id}">
                        </div>
                        <div class="form-group">
                            <label style="display:inline-table">装料口
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <select name="load_site">
                                <option>--请选择装料口--</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label style="display:inline-table">标号
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <input type="text" value="{$data['grade']}" name="grade" />
                        </div>
                        <div class="form-group">
                            <label style="display:inline-table">施工部位
                                <i class="fa fa-pencil-square-o"></i>:</label>
                            <input type="text" value="{$data['components']}" name="components" />
                        </div>
                        <div style="clear: both;"></div>
                        <div class="box-footer">
                            <span class="input-group-btn">
                                <button class="btn btn-danger pull-left" type="button"  id="close-dialog">取消</button>
                                <button class="btn btn-primary pull-right" type="button" id='site_public_editinfo_form_submit'>提交</button>
                            </span>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function formatRepo(data) {
            if (!data.task_from) { // adjust for custom placeholder values
                return '正在加载..';
            }
            $("#sitelonglat").val(data.task_from_longitude+','+data.task_from_latitude)
            return data.task_from+"-"+data.task_end;
        }
        function formatRepoSelection(data, container) {
            if (!data.task_from) { // adjust for custom placeholder values
                return '请输入线路编号或起始站点';
            }
            var load_num= data.load_num;
            $("select[name='load_site']").html("");
            for(var i=1;i<=load_num;i++){
                $("select[name='load_site']").append('<option value="'+i+'">'+i+'</option>');
            }
            return  data.task_from+"-"+data.task_end;
        }
        $(function () {
            $('.date').datepicker({language:'zh-CN','autoclose':true});
            $(".select2").select2({minimumResultsForSearch: -1});
            $("select[name='roads_id']").select2({
//                placeholder: "请输入线路编号或起始站点",
                allowClear: true,
                ajax: {
                    url: "{:U('Task/roadsSearch')}",
                    dataType: 'json',
                    cache: true,
                    delay: 300,
                    data: function (params) {
                        return {
                            key: params.term, // search term
                            page: params.page
                        };
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        return {
                            results: data.items,
                            pagination: {
                                more: (params.page * 30) < data.total_count
                            }
                        };
                    },
                    cache: true
                },
                escapeMarkup: function (markup) {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 0,
                templateResult: formatRepo,
                templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
            });
            $('#site_public_editinfo_form_submit').click(function () {
                $('#site_public_editinfo_form').submit();
            });
            $.validate({
                onSuccess: function () {
                    publicEditinfoFormSubmit();
                    return false;
                }
            });
            if("{$data['task_from']}"!=""){
                $(".task .select2-selection__rendered").html("{$data['task_from']}-{$data['task_end']}");
            }
            $("#sitelonglat").val('{$data["task_from_longitude"]},{$data["task_from_latitude"]}')

            var load_num = "{$site['load_num']}";
            $("select[name='load_site']").html("");
            for(var i=1;i<=load_num;i++){
                $("select[name='load_site']").append('<option value="'+i+'">'+i+'</option>');
            }
            $("select[name='load_site']").val('{$data["load_site"]}');
        });

        function publicEditinfoFormSubmit() {
            $.post("{:U('Task/add')}",
                    $("#site_public_editinfo_form").serialize(), function (res) {
                if (!res.status) {
                    $.messager.alert('提示信息', res.info, 'error');
                } else {
                    $.messager.alert('提示信息', res.info, 'info');
                    dialog.get('dialogPage').close().remove();
                    taskTable.fnDraw(false);
                }
            });
            return false;
        }


        function getCar(){
            var load= $("input[name='total_load']");
            if(load.val()==""||!$.isNumeric(load.val())||load.val()==0){
                $.messager.alert('提示信息', '请填写运输方量', 'error');
                return;
            }
            var roadsid  = $("select[name='roads_id']");
            if(roadsid.val()==""){
                $.messager.alert('提示信息', '请先选择线路', 'error');
                return;
            }
            var lonlat = $("#sitelonglat").val();
            var lons = lonlat.split(',');
            var url = '{:U("Task/getCar")}?lng='+lons[0]+"&lat="+lons[1]+"&roadsid="+roadsid.val()+"&load="+load.val();
            $.dialog(url, '选择车辆', null,66,'onlinecar');
        }
    </script>
</section>